<%
/**
 * 描述：　资源分配情况
 *　created by amon 2005-1-10
 */
%>
<%@ include file = "/common/ini.jsp"%>
<%@ include file = "/common/_log4j.jsp"%>
<%@ include file = "/common/_ApplicationContext_init.jsp"%>
<%@ include file = "/common/_vr.jsp"%>
<%@ include file = "/js/_js_for_select.jsp"%>
<%
        String tId = request.getParameter("tId");
        int tType = Integer.parseInt(request.getParameter("tType"));
        String serviceURL = null;
        Manager manager = null;
        switch(tType)
        {
            case SysFrameParams.ORG: 
            {
                logger.debug("机构");
                manager = (Manager)applicationContext.getBean("orgManager");
                serviceURL = "sysframe.org.AddViews2OrgService";
                break;
            }
            case SysFrameParams.ROLE: 
            {
                logger.debug("角色");
                manager = (Manager)applicationContext.getBean("roleManager");
                serviceURL = "sysframe.role.AddViews2RoleService";
                break;
            }
            case SysFrameParams.POST: 
            {
                logger.debug("岗位");
                manager = (Manager)applicationContext.getBean("postManager");
                serviceURL = "sysframe.post.AddViews2PostService";
                break;
            }
            default:
            {
                throw new Exception("未知类型tType:" + tType);
            }
        };
        //
        Unit unit = (Unit)manager.get(tId);;
        // 每行显示个数
        int countPerTr = 4;
%>
<%
    HomeManager homeManager = (HomeManager)applicationContext.getBean("homeManager");
    Object[] homes = homeManager.findAllHomes().toArray();
    int areaCount = 0;
%>
<html>
    <%@ include file = "/css/detailcss.jsp"%>
    <head><title>授权情况</title></head>
    <script>
        function hideAllAreas()
        {
            var count = getLength(detailForm.homes);
            for(var i = 0; i < count; i ++)
            {
                try
                {
                    eval("detailForm.area" + i + ".style.display = 'none';");
                }
                catch(err)
                {
                    alert("hideAllAreas() " + err);
                }
            }
        }
        
        function showArea(homeId)
        {
            hideAllAreas();
            hideAllColumns();
            if(homeId == "")
            {
                return;
            }
            try
            {
                eval("detailForm.areas_" + homeId  + ".style.display = '';");
                eval("showColumns(detailForm.areas_" + homeId  + ".value);");
            }
            catch(err)
            {
                alert("showArea()" + err);
            }
        }

        function showColumns(areaId)
        {
            hideAllColumns();
            if(areaId == "")
            {
                return;
            }
            try
            {
                eval("columns" + areaId  + ".style.display = '';");
            }
            catch(err)
            {
                alert("showColumns()" + err);
            }
        }
    </script>
<table width="100%" height="100%" >
    <tr>
        <td valign="top">
            <form name="detailForm" method="post" action="Controller.jsp">
                <B>主页:</B> <select name="homes" style="width:1in;" onchange="showArea(this.value)"></select>
                &nbsp;&nbsp; &nbsp;&nbsp; <B>分区:</B>
                <%
                    List allAreas = new Vector();
                    // homes
                    for(int i = 0; i < homes.length; i ++)
                    {
                        Home home = (Home)homes[i];
                        %>
                            <select style="display:none;width:1in;" id="area<%= i%>" onchange="showColumns(this.value)" name="areas_<%= home.getId()%>" >
                            </select>
                            <script>
                                addOption(detailForm.homes,"<%= home.getId()%>","<%= home.getName()%>");
                            </script>
                        <%
                        Object[] areas = home.getAreas().toArray();
                        // areas
                        for(int j = 0; j < areas.length; j ++)
                        {
                            areaCount ++;
                            Area area  = (Area)areas[j];
                            allAreas.add(area);
                            %>
                            <script>
                                addOption(detailForm.areas_<%= home.getId()%>,"<%= area.getId()%>","<%= area.getName()%>");
                            </script>
                            <%
                            // columns
                            Object[] column1s = area.getColumns().toArray();
                            %><%@ include file = "_columns.jsp"%><%
                        }//for j
                    }//for i
                %>
                <input type="hidden" name="serviceURL" value="<%= serviceURL%>">
                <input type="hidden" name="id" value="<%= tId%>">
            </form>
        </td>        
    <tr>
    <tr>
        <td height="20" align="center">
            &nbsp;&nbsp;<font color="red"><%= vr.getErrMess("name")%></font>
    </td>
    </tr>
    <tr>
        <td height="20" valign="bottom" align="center">
            <input type="button" value="保存" onclick="detailForm.submit();this.disabled=true;">&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="重置" onclick="this.disabled=true;window.location.reload();">&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="取消" onclick="window.close();">
        </td>
    </tr>
    <script>
        <%
        if(homes.length > 0)
        {
            Home home = (Home)homes[0];
            %>showArea("<%= home.getId()%>");<%
        }
        %>
        <%
        // 初始化已经授权了的二级栏目
        Object[] c2s = unit.getColumn2s().toArray();
        for(int i = 0; i < c2s.length; i ++)
        {
            Column column = (Column)c2s[i];
            %>detailForm.column<%= column.getId()%>.checked = true;<%
        }//for i
        %>
        function hideAllColumns()
        {
            try
            {
                <%
                for(int i = 0; i < allAreas.size(); i ++)    
                {
                    Area area = (Area)allAreas.get(i);
                    %>eval("columns<%= area.getId()%>.style.display = 'none';");<%
                }// for i
                %>
            }
            catch(err)
            {
                alert("hideAllAreas()" + err);
            }
        }
    </script>
</html>
